package ru.rchervot.sanasar.client.model;

import com.google.inject.Inject;

import ru.rchervot.sanasar.client.model.filters.Filter;
import ru.rchervot.sanasar.client.model.filters.FilterFullText;
import ru.rchervot.sanasar.client.model.filters.FilterItemIds;
import ru.rchervot.sanasar.client.model.filters.FilterItemName;

public class FactoryQueryCandidatesDefault implements FactoryQueryCandidates {
	
	private int pageSize;
	
	@Inject
	public FactoryQueryCandidatesDefault() {
	}

	@Override
	public Query buildByQueryId(int queryId, int offset, int userId) {
		Query q = new DefaultQuery(pageSize, userId);
		q.setID(queryId);
		q.setOffset(offset);
		
		return q;
	}
	
	@Override
	public Query buildFromQuickSearch(String quickSearchQuery, int userId) {
		FilterItemName f = new FilterItemName();
		f.setItemNameInclude(quickSearchQuery);
		
		Query q = new DefaultQuery(pageSize, userId);
		q.addFilter(f);
		
		return q;
	}

	// TODO should remove this, and make pageSize final  
	@Override
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	@Override
	public Query buildEmptyQuery(int userId) {
		Query q = new DefaultQuery(pageSize, userId);
		
		return q;
	}

	@Override
	public Filter buildFilter(String filterName) {
		if (filterName != null) {
			if (filterName.equalsIgnoreCase(FilterFullText.NAME)) {
				return new FilterFullText();
			} else if (filterName.equalsIgnoreCase(FilterItemIds.NAME)) {
				return new FilterItemIds();
			}
		}
		return null;
	}
	
}
